<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Pdf module usage example - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.pdf.usage.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.pdf.usage.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.pdf.info.html">Document Info and Metadata</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.pdf.html">Zend_Pdf</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.progressbar.html">Zend_ProgressBar</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.pdf.usage" class="section"><div class="info"><h1 class="title">Zend_Pdf module usage example</h1></div>
    

    <p class="para">
        This section provides an example of module usage.
    </p>

    <p class="para">
        This example can be found in a <var class="filename">demos/Zend/Pdf/demo.php</var> file.
    </p>

    <p class="para">
        There are also <var class="filename">test.pdf</var> file, which can be used with this demo
        for test purposes.
    </p>

    <div class="example" id="zend.pdf.usage.example-1"><div class="info"><p><b>Example #1 Zend_Pdf module usage demo</b></p></div>
        

        <pre class="programlisting brush: php">
/**
 * @package Zend_Pdf
 * @subpackage demo
 */

if (!isset($argv[1])) {
    echo &quot;USAGE: php demo.php &lt;pdf_file&gt; [&lt;output_pdf_file&gt;]\n&quot;;
    exit;
}

try {
    $pdf = Zend_Pdf::load($argv[1]);
} catch (Zend_Pdf_Exception $e) {
    if ($e-&gt;getMessage() == &#039;Can not open \&#039;&#039; . $argv[1] .
                            &#039;\&#039; file for reading.&#039;) {
        // Create new PDF if file doesn&#039;t exist
        $pdf = new Zend_Pdf();

        if (!isset($argv[2])) {
            // force complete file rewriting (instead of updating)
            $argv[2] = $argv[1];
        }
    } else {
        // Throw an exception if it&#039;s not the &quot;Can&#039;t open file
        // exception
        throw $e;
    }
}

//------------------------------------------------------------------------
// Reverse page order
$pdf-&gt;pages = array_reverse($pdf-&gt;pages);

// Create new Style
$style = new Zend_Pdf_Style();
$style-&gt;setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0.9));
$style-&gt;setLineColor(new Zend_Pdf_Color_GrayScale(0.2));
$style-&gt;setLineWidth(3);
$style-&gt;setLineDashingPattern(array(3, 2, 3, 4), 1.6);
$fontH = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
$style-&gt;setFont($fontH, 32);

try {
    // Create new image object
    $imageFile = dirname(__FILE__) . &#039;/stamp.jpg&#039;;
    $stampImage = Zend_Pdf_Image::imageWithPath($imageFile);
} catch (Zend_Pdf_Exception $e) {
    // Example of operating with image loading exceptions.
    if ($e-&gt;getMessage() != &#039;Image extension is not installed.&#039; &amp;&amp;
        $e-&gt;getMessage() != &#039;JPG support is not configured properly.&#039;) {
        throw $e;
    }
    $stampImage = null;
}

// Mark page as modified
foreach ($pdf-&gt;pages as $page){
    $page-&gt;saveGS()
         -&gt;setAlpha(0.25)
         -&gt;setStyle($style)
         -&gt;rotate(0, 0, M_PI_2/3);

    $page-&gt;saveGS();
    $page-&gt;clipCircle(550, -10, 50);
    if ($stampImage != null) {
        $page-&gt;drawImage($stampImage, 500, -60, 600, 40);
    }
    $page-&gt;restoreGS();

    $page-&gt;drawText(&#039;Modified by Zend Framework!&#039;, 150, 0)
         -&gt;restoreGS();
}

// Add new page generated by Zend_Pdf object
// (page is attached to the specified the document)
$pdf-&gt;pages[] = ($page1 = $pdf-&gt;newPage(&#039;A4&#039;));

// Add new page generated by Zend_Pdf_Page object
// (page is not attached to the document)
$page2 = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE);
$pdf-&gt;pages[] = $page2;

// Create new font
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

// Apply font and draw text
$page1-&gt;setFont($font, 36)
      -&gt;setFillColor(Zend_Pdf_Color_Html::color(&#039;#9999cc&#039;))
      -&gt;drawText(&#039;Helvetica 36 text string&#039;, 60, 500);

// Use font object for another page
$page2-&gt;setFont($font, 24)
      -&gt;drawText(&#039;Helvetica 24 text string&#039;, 60, 500);

// Use another font
$fontT = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES);
$page2-&gt;setFont($fontT, 32)
      -&gt;drawText(&#039;Times-Roman 32 text string&#039;, 60, 450);

// Draw rectangle
$page2-&gt;setFillColor(new Zend_Pdf_Color_GrayScale(0.8))
      -&gt;setLineColor(new Zend_Pdf_Color_GrayScale(0.2))
      -&gt;setLineDashingPattern(array(3, 2, 3, 4), 1.6)
      -&gt;drawRectangle(60, 400, 400, 350);

// Draw circle
$page2-&gt;setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID)
      -&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0))
      -&gt;drawCircle(85, 375, 25);

// Draw sectors
$page2-&gt;drawCircle(200, 375, 25, 2*M_PI/3, -M_PI/6)
      -&gt;setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0))
      -&gt;drawCircle(200, 375, 25, M_PI/6, 2*M_PI/3)
      -&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0))
      -&gt;drawCircle(200, 375, 25, -M_PI/6, M_PI/6);

// Draw ellipse
$page2-&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0))
      -&gt;drawEllipse(250, 400, 400, 350)
      -&gt;setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0))
      -&gt;drawEllipse(250, 400, 400, 350, M_PI/6, 2*M_PI/3)
      -&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0))
      -&gt;drawEllipse(250, 400, 400, 350, -M_PI/6, M_PI/6);

// Draw and fill polygon
$page2-&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 1));
$x = array();
$y = array();
for ($count = 0; $count &lt; 8; $count++) {
    $x[] = 140 + 25*cos(3*M_PI_4*$count);
    $y[] = 375 + 25*sin(3*M_PI_4*$count);
}
$page2-&gt;drawPolygon($x, $y,
                    Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
                    Zend_Pdf_Page::FILL_METHOD_EVEN_ODD);

// ----------- Draw figures in modified coordination system --------------

// Coordination system movement
$page2-&gt;saveGS();
$page2-&gt;translate(60, 250); // Shift coordination system

// Draw rectangle
$page2-&gt;setFillColor(new Zend_Pdf_Color_GrayScale(0.8))
      -&gt;setLineColor(new Zend_Pdf_Color_GrayScale(0.2))
      -&gt;setLineDashingPattern(array(3, 2, 3, 4), 1.6)
      -&gt;drawRectangle(0, 50, 340, 0);

// Draw circle
$page2-&gt;setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID)
      -&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0))
      -&gt;drawCircle(25, 25, 25);

// Draw sectors
$page2-&gt;drawCircle(140, 25, 25, 2*M_PI/3, -M_PI/6)
      -&gt;setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0))
      -&gt;drawCircle(140, 25, 25, M_PI/6, 2*M_PI/3)
      -&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0))
      -&gt;drawCircle(140, 25, 25, -M_PI/6, M_PI/6);

// Draw ellipse
$page2-&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0))
      -&gt;drawEllipse(190, 50, 340, 0)
      -&gt;setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0))
      -&gt;drawEllipse(190, 50, 340, 0, M_PI/6, 2*M_PI/3)
      -&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0))
      -&gt;drawEllipse(190, 50, 340, 0, -M_PI/6, M_PI/6);

// Draw and fill polygon
$page2-&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 1));
$x = array();
$y = array();
for ($count = 0; $count &lt; 8; $count++) {
    $x[] = 80 + 25*cos(3*M_PI_4*$count);
    $y[] = 25 + 25*sin(3*M_PI_4*$count);
}
$page2-&gt;drawPolygon($x, $y,
                    Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
                    Zend_Pdf_Page::FILL_METHOD_EVEN_ODD);

// Draw line
$page2-&gt;setLineWidth(0.5)
      -&gt;drawLine(0, 25, 340, 25);

$page2-&gt;restoreGS();

// Coordination system movement, skewing and scaling
$page2-&gt;saveGS();
$page2-&gt;translate(60, 150)     // Shift coordination system
      -&gt;skew(0, 0, 0, -M_PI/9) // Skew coordination system
      -&gt;scale(0.9, 0.9);       // Scale coordination system

// Draw rectangle
$page2-&gt;setFillColor(new Zend_Pdf_Color_GrayScale(0.8))
      -&gt;setLineColor(new Zend_Pdf_Color_GrayScale(0.2))
      -&gt;setLineDashingPattern(array(3, 2, 3, 4), 1.6)
      -&gt;drawRectangle(0, 50, 340, 0);

// Draw circle
$page2-&gt;setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID)
      -&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0))
      -&gt;drawCircle(25, 25, 25);

// Draw sectors
$page2-&gt;drawCircle(140, 25, 25, 2*M_PI/3, -M_PI/6)
      -&gt;setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0))
      -&gt;drawCircle(140, 25, 25, M_PI/6, 2*M_PI/3)
      -&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0))
      -&gt;drawCircle(140, 25, 25, -M_PI/6, M_PI/6);

// Draw ellipse
$page2-&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0))
      -&gt;drawEllipse(190, 50, 340, 0)
      -&gt;setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0))
      -&gt;drawEllipse(190, 50, 340, 0, M_PI/6, 2*M_PI/3)
      -&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0))
      -&gt;drawEllipse(190, 50, 340, 0, -M_PI/6, M_PI/6);

// Draw and fill polygon
$page2-&gt;setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 1));
$x = array();
$y = array();
for ($count = 0; $count &lt; 8; $count++) {
    $x[] = 80 + 25*cos(3*M_PI_4*$count);
    $y[] = 25 + 25*sin(3*M_PI_4*$count);
}
$page2-&gt;drawPolygon($x, $y,
                    Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE,
                    Zend_Pdf_Page::FILL_METHOD_EVEN_ODD);

// Draw line
$page2-&gt;setLineWidth(0.5)
      -&gt;drawLine(0, 25, 340, 25);

$page2-&gt;restoreGS();

//------------------------------------------------------------------------

if (isset($argv[2])) {
    $pdf-&gt;save($argv[2]);
} else {
    $pdf-&gt;save($argv[1], true /* update */);
}
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.pdf.info.html">Document Info and Metadata</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.pdf.html">Zend_Pdf</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.progressbar.html">Zend_ProgressBar</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.pdf.html">Zend_Pdf</a></li>
  <li><a href="zend.pdf.introduction.html">Introduction</a></li>
  <li><a href="zend.pdf.create.html">Creating and Loading PDF Documents</a></li>
  <li><a href="zend.pdf.save.html">Save Changes to PDF Documents</a></li>
  <li><a href="zend.pdf.pages.html">Working with Pages</a></li>
  <li><a href="zend.pdf.drawing.html">Drawing</a></li>
  <li><a href="zend.pdf.interactive-features.html">Interactive Features</a></li>
  <li><a href="zend.pdf.info.html">Document Info and Metadata</a></li>
  <li class="active"><a href="zend.pdf.usage.html">Zend_Pdf module usage example</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>